using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ERPBackend.Models
{
    public class SalesOrder : BaseModel
    {
        /// <summary>
        /// 订单编号
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string OrderCode { get; set; }

        /// <summary>
        /// 订单名称
        /// </summary>
        [Required]
        [MaxLength(255)]
        public string OrderName { get; set; }

        /// <summary>
        /// 客户ID
        /// </summary>
        [Required]
        public int CustomerId { get; set; }

        /// <summary>
        /// 客户
        /// </summary>
        [ForeignKey("CustomerId")]
        public Customer Customer { get; set; }

        /// <summary>
        /// 销售合同ID
        /// </summary>
        public int? SalesContractId { get; set; }

        /// <summary>
        /// 销售合同
        /// </summary>
        [ForeignKey("SalesContractId")]
        public SalesContract SalesContract { get; set; }

        /// <summary>
        /// 订单日期
        /// </summary>
        [Required]
        public DateTime OrderDate { get; set; }

        /// <summary>
        /// 期望交付日期
        /// </summary>
        public DateTime? ExpectedDeliveryDate { get; set; }

        /// <summary>
        /// 实际交付日期
        /// </summary>
        public DateTime? ActualDeliveryDate { get; set; }

        /// <summary>
        /// 订单状态（0:待审核, 1:已审核, 2:已关闭, 3:已拒绝）
        /// </summary>
        [Required]
        public int Status { get; set; }

        /// <summary>
        /// 订单总金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal TotalAmount { get; set; }

        /// <summary>
        /// 已收款金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal ReceivedAmount { get; set; }

        /// <summary>
        /// 未收款金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal UnpaidAmount { get; set; }

        /// <summary>
        /// 付款条件
        /// </summary>
        [MaxLength(255)]
        public string PaymentTerms { get; set; }

        /// <summary>
        /// 交付条件
        /// </summary>
        [MaxLength(255)]
        public string DeliveryTerms { get; set; }

        /// <summary>
        /// 订单备注
        /// </summary>
        public string Remarks { get; set; }

        /// <summary>
        /// 审核人ID
        /// </summary>
        public int? ApprovedBy { get; set; }

        /// <summary>
        /// 审核时间
        /// </summary>
        public DateTime? ApprovedTime { get; set; }

        /// <summary>
        /// 关闭原因
        /// </summary>
        public string CloseReason { get; set; }

        /// <summary>
        /// 关闭人ID
        /// </summary>
        public int? ClosedBy { get; set; }

        /// <summary>
        /// 关闭时间
        /// </summary>
        public DateTime? ClosedTime { get; set; }

        /// <summary>
        /// 销售订单明细
        /// </summary>
        public List<SalesOrderItem> SalesOrderItems { get; set; } = new List<SalesOrderItem>();
    }
}